﻿using System.Data.Entity;
using System.Data.Entity.Migrations;
using InformationCenter.Models;

namespace InformationCenter.SQLHelper
{
    public class WebDbContext : DbContext
    {
        public WebDbContext()
            : base("WebDbContainer")
        {
            Database.SetInitializer(new WebDbInitializer());
        }

        //实体类
        public DbSet<WebMaint> WebMaints { get; set; }
        public DbSet<UserInfo> UserInfos { get; set; }

        public DbSet<ColumnList> ColumnLists { get; set; }
        public DbSet<ArticleList> ArticleLists { get; set; }
        public DbSet<Category> Categories { get; set; }
        public DbSet<ItemList> ItemLists { get; set; }
          
    }

    /// <summary>
    /// 数据库初始化，可以在Seed中写入测试数据
    /// </summary>
    public class WebDbInitializer : DropCreateDatabaseIfModelChanges<WebDbContext>
    {
        protected override void Seed(WebDbContext context)
        {
            context.UserInfos.Add(new UserInfo
            {
                Name = "sora",
                Password = "qwe123",
                Nickname = "SoraChen",
                Logincount = 0,
                Mail = "lushen@lushen.com",
                Locked = false
            });

            context.WebMaints.Add(new WebMaint
            {
                Id = 1,
                Webname = "撸神国际",
                Seo = "国际",
                SeoDesc = ",描述是个酱油党",
                VersionInfo = "2016",
                LicenseNo = "沪88888888",
                Email = "lushen@lushen.com"
            });

            context.Categories.AddOrUpdate(p=>p.Name,
                new Category{Id = 1,Name = "悬疑",Value = "xuanyi"},
                  new Category {Id = 2,Name = "娱乐", Value = "yule"}
              );
        }
    }
}